//
//  ChouCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/3.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#define LuColor [UIColor colorWithHexString:@"#53b279"]
#import "ChouCell.h"

@implementation ChouCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
         [self createUI];
        UILabel *orageLab = [[UILabel alloc] init];
        orageLab.backgroundColor = OverColor;
        [self addSubview:orageLab];
        [orageLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(3, 45));
            make.left.mas_equalTo(self.mas_left).offset(1);
            make.top.equalTo(self.mas_top).offset(7);
            
        }];
        _photoImg= [[UIImageView alloc] init];
        _photoImg.image = [UIImage imageNamed:@"nanshihui"];
        [self addSubview:_photoImg];
        [_photoImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(17);
            make.top.equalTo(self.mas_top).offset(10);
            make.left.equalTo(self.mas_left).offset(10);
        }];
       
        _nameLab = [[UILabel alloc] init];
        _nameLab.text = @"耶律花花";
        _nameLab.textColor = OverColor;
        _nameLab.font = [UIFont systemFontOfSize:14];
        [self addSubview:_nameLab];
        [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(50, 16));
            make.left.equalTo(_photoImg.mas_right).offset(2);
            make.top.mas_equalTo(self.mas_top).offset(12);
        }];
        
        _shiLab = [[UILabel alloc] init];
        _shiLab.textColor = [UIColor blackColor];
        _shiLab.text = @"认筹时间 | 2016-10-29";
        _shiLab.font = [UIFont systemFontOfSize:10];
        [self addSubview:_shiLab];
        [_shiLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(120, 14));
            make.left.equalTo(_nameLab.mas_right).offset(5);
            make.top.equalTo(self.mas_top).offset(13);
        }];
        
        _guLab = [[UILabel alloc] init];
        _guLab.textColor = [UIColor blackColor];
        _guLab.text = @"置业顾问 | 农夫";
        _guLab.font = [UIFont systemFontOfSize:10];
        _guLab.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_guLab];
        [_guLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(110, 14));
            make.left.equalTo(_shiLab.mas_right).offset(8);
            make.top.equalTo(self.mas_top).offset(13);
        }];

        
        
        
        _vipLab = [[UILabel alloc] init];
        _vipLab.text = @"VIP 120";
        _vipLab.textColor = [UIColor colorWithHexString:@"#53b279"];
        _vipLab.font = [UIFont systemFontOfSize:10];
        [self addSubview:_vipLab];
        [_vipLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(90, 14));
            make.left.equalTo(self.mas_left).offset(15);
            make.top.equalTo(self.mas_top).offset(40);
        }];
        
        _haoLab = [[UILabel alloc] init];
        _haoLab.text = @"| 市场排号 |";
        _haoLab.textColor = [UIColor colorWithHexString:@"#53b279"];
        _haoLab.font = [UIFont systemFontOfSize:10];
        [self addSubview:_haoLab];
        [_haoLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 14));
            make.left.equalTo(_vipLab.mas_right).offset(5);
            make.top.equalTo(self.mas_top).offset(40);
        }];
        
        _jiaoLao = [[UILabel alloc] init];
        
        _jiaoLao = [[UILabel alloc] init];
        _jiaoLao.text = @"已成交";
        _jiaoLao.textColor = [UIColor colorWithHexString:@"#53b279"];
        _jiaoLao.font = [UIFont systemFontOfSize:10];
        [self addSubview:_jiaoLao];
        [_jiaoLao mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 14));
            make.left.equalTo(_haoLab.mas_right).offset(5);
            make.top.equalTo(self.mas_top).offset(40);
        }];
        
        _chouLab =  [[UILabel alloc] init];
        _chouLab.text = @"未退筹";
        _chouLab.textColor = [UIColor colorWithHexString:@"#53b279"];
        _chouLab.font = [UIFont systemFontOfSize:10];
        [self addSubview:_chouLab];
        [_chouLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 14));
            make.left.equalTo(_jiaoLao.mas_right).offset(5);
            make.top.equalTo(self.mas_top).offset(40);
        }];
        

        
        
        
        
        _messageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _messageBtn.layer.cornerRadius = 15;
        [_messageBtn setImage:[UIImage imageNamed:@"xinxi"] forState:0];
        [_messageBtn addTarget:self action:@selector(messageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_messageBtn];
        [_messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(25);
            make.top.equalTo(self.mas_top).offset(18);
            make.right.equalTo(self.mas_right).offset(-50);
        }];
        
        _callBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _callBtn.userInteractionEnabled = NO;
        _callBtn.layer.cornerRadius = 15;
        [_callBtn setImage:[UIImage imageNamed:@"dianhuatubiao"] forState:0];
//        [_callBtn addTarget:self action:@selector(callBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_callBtn];
        [_callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(25);
            make.top.equalTo(self.mas_top).offset(18);
            make.right.equalTo(self.mas_right).offset(-10);
        }];
        
        _callUpBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _callUpBtn.layer.cornerRadius = 15;
//        [_callUpBtn setImage:[UIImage imageNamed:@"dianhuatubiao"] forState:0];
        [_callUpBtn addTarget:self action:@selector(callBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_callUpBtn];
        [_callUpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(60);
            make.top.equalTo(self.mas_top).offset(0);
            make.right.equalTo(self.mas_right).offset(0);
        }];
        
        _phoneNumber = [[UILabel alloc] init];
    }
    return self;
}



-(void)setUpRenChouCellWithName:(NSString *)_name AndDate:(NSString *)_date AndNumber:(NSString *)_number AndPaiType:(NSString *)_type AndTaiDeal:(NSString *)_deal AndPhone:(NSString *)_phone andGuWen:(NSString *)_gu andTuiChou:(NSString *)_chou
{
    
    _nameLab.text = _name;
    _shiLab.text = [NSString stringWithFormat:@"认筹时间 : %@",_date];
    _vipLab.text = [NSString stringWithFormat:@"VIP  %@",_number];
    _haoLab.text = _type;
    _jiaoLao.text = _deal;
       
    _phoneNumber.text = _phone;
    
    _chouLab.text = _chou;
    NSString *IDA = [[NSUserDefaults standardUserDefaults] objectForKey:@"STATE"];
    NSLog(@"=======IDA==%@",IDA);
    if ([IDA isEqualToString: @"1"])
    {
        _guLab.text = nil;
       // _chouLab.text = nil;
    }
    else
    {
        _guLab.text = [NSString stringWithFormat:@"置业顾问 | %@",_gu];
       // _chouLab.text = _chou;
    }
  
}

//重点在这里
- (void)createUI{
    //创建一个UIView比self.contentView小一圈
    self.bgView  = [[UIView alloc] initWithFrame:CGRectMake(0,5, [[UIScreen mainScreen] bounds].size.width, 54)];
    self.bgView.backgroundColor = [UIColor whiteColor];
    //给bgView边框设置阴影
    self.bgView.layer.shadowOffset = CGSizeMake(2,2);
    self.bgView.layer.shadowOpacity = 0.8;
    self.bgView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    [self.contentView addSubview:self.bgView];
}

#pragma mark 按钮的点击事件
-(void)messageBtnClick:(UIButton *)btn
{
    self.userInteractionEnabled = NO;
    btn.userInteractionEnabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        btn.userInteractionEnabled = YES;
        self.userInteractionEnabled = YES;
    });
    
    NSString *phoneStr = _phoneNumber.text;
    NSString *xlStr = [phoneStr stringByReplacingOccurrencesOfString:@" " withString:@""];
     NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"sms:%@",str];
    NSURL *url = [NSURL URLWithString:str];
  
    [[UIApplication sharedApplication] openURL:url];
}

-(void)callBtnClick:(UIButton *)btn
{
    self.userInteractionEnabled = NO;
    btn.userInteractionEnabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        btn.userInteractionEnabled = YES;
        self.userInteractionEnabled = YES;
    });
    if (_delegate && [_delegate respondsToSelector:@selector(didSelectPhone:)]) {
        [_delegate didSelectPhone:_indexPath];
    }
//    NSString *phoneStr = _phoneNumber.text;
//    NSString *xlStr = [phoneStr stringByReplacingOccurrencesOfString:@" " withString:@""];
//    NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",xlStr];
//    UIWebView *callWebview = [[UIWebView alloc] init];
//    [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
//    [self addSubview:callWebview];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
